﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for BLLPackageManagement
/// </summary>
public class BLLPackageManagement
{

    #region Constructor

    public BLLPackageManagement()
    {

    }

    #endregion

    #region package Management
    DALPackage dalPackage = new DALPackage();
    DALPayment dalPayment = new DALPayment();



    public tblPackage GetPackage(int id)
    {
        DALPackage dal = new DALPackage();
        return dal.getPackage(id);
    }

    public tblPackage GetPackage(string barcode)
    {
        return dalPackage.getPackage(barcode);
    }

    public void UpdatePackage()
    {
        dalPackage.updatePackage();
    }

    public vPackageDetail GetvPackage(string barcode)
    {
        return dalPackage.GetvPackage(barcode);
    }

    public List<vPackageDetail> GetvPackagesByUseremail(string email)
    {
        return dalPackage.GetvPackagesByEmail(email);
    }

    public List<vPackageDetail> GetvProgressPackagesByUseremail(string email)
    {
        return dalPackage.GetvProgressPackagesByEmail(email);
    }

    public List<vPackageDetail> GetvCompletedPackagesByUseremail(string email)
    {
        return dalPackage.GetvCompletedPackagesByEmail(email);
    }

    public List<vPackageDetail> ListPackages()
    {
        return dalPackage.ListPackages();
    }

    public List<vPackageDetail> ListPackages(DateTime dt)
    {
        return dalPackage.ListPackages(dt);
    }

    //Payment Portion
    public tblPayment GetPayment(int id)
    {
        return dalPayment.getPayment(id);
    }

    public void UpdatePayment()
    {
        dalPayment.updatePayment();
    }


    #endregion

    #region Transit Management

    DALTransit dalTransit = new DALTransit();
    public List<vTransitRecord> ListTransitByPackageID(int packageid)
    {
        return dalTransit.GetPackagevTransits(packageid);
    }

    public tblTransit GetTransit(int transitid)
    {
        return dalTransit.GetTransit(transitid);
    }

    public tblTransit GetTransit(int packageid, int branchid)
    {
        return dalTransit.GetTransit(packageid, branchid);
    }

    public tblTransit GetFirstTransit(int packageid)
    {
        return dalTransit.GetFirstPackageTransit(packageid);
    }

    public tblTransit GetLastTransit(int packageid)
    {
        return dalTransit.GetLastPackageTransit(packageid);
    }

    public bool DelTransit(int transitid)
    {
        try
        {
            tblTransit pre_transit = dalTransit.getPreTransit(transitid);
            tblTransit cur_transit = dalTransit.GetTransit(transitid);
            pre_transit.NextTransitID = cur_transit.NextTransitID;

            dalTransit.DelTransit(transitid);
            return true;
        }
        catch { return false; }
    }

    public void NewTransit(tblTransit transit)
    {
        dalTransit.InsertNewTransit(transit);
    }

    public void UpdateTransit()
    {
        dalTransit.Update();
    }



    #endregion

    #region Branch

    public List<tblBranch> ListBranches()
    {
        DALBranch dal = new DALBranch();
        return dal.ListBranches();
    }

    public List<tblBranch> ListBranches(string barcode)
    {
        DALBranch dal = new DALBranch();
        return dal.ListBranches(barcode);
    }

    public tblBranch GetBranch(int id)
    {
        DALBranch dal = new DALBranch();
        return dal.GetBranch(id);
    }

    #endregion


    public List<tblCountry> getCountries()
    {
        DALCountry dal = new DALCountry();
        return dal.getCountries();
    }

    public List<tblStatus> ListPackageStatus()
    {
        DALStatus dal = new DALStatus();
        return dal.ListStatus();
    }

    public tblStatus GetStatus(string statusname)
    {
        DALStatus dal = new DALStatus();
        return dal.GetStatus(statusname);
    }


    
}